const router = require('koa-router')();
const {login} = require('../function/user.js')
router.prefix('/api/user');

router.post('/login', async (ctx, next) => {
	// 获取post传入的数据
	const { username,password } = ctx.request.body;
	let res = await login(username,password)
	ctx.session.username = res[0].username;
	ctx.body = {
		postData:{
			username,
			password
		},
		errorno:0,
		data: res[0]
	};
});

router.get('/session-test',async (ctx,next) => {
	if(ctx.session.viewNum == null){
		ctx.session.viewNum = 0;
	}
	ctx.session.viewNum++;
	ctx.body = {
		errno:0,
		data:ctx.session.viewNum
	};
});

module.exports = router;